package org.jeecg.controller;

import org.jeecg.client.BizResponse;
import org.jeecg.client.DataSet;
import org.jeecg.client.SendUtils;
import org.jeecg.common.api.vo.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Description App业务终端
 * @Author wangyi
 * @Date 2022/9/7 15:57
 * @Version 1.0
 **/
@RestController
@RequestMapping("/uapp")
public class UappController {

    @RequestMapping("runDb")
    public Result runDb(String sql){
        try {
            DataSet dataSet = SendUtils.sendRunDbCmd(sql);
            return Result.OK(dataSet.getTables());
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }

    @RequestMapping("runCmd")
    public Result runCmd( @RequestBody Map<String,String> map){
        try {
            BizResponse bizResponse = SendUtils.sendRunCmd(map);
            return Result.OK(bizResponse);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }

    @RequestMapping("runCmdDj")
    public Result runCmdDj( @RequestBody Map<String,String> map){
        try {
            BizResponse bizResponse = SendUtils.runCmdDj(map);
            return Result.OK(bizResponse);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }
}
